<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>AES 测试</title>
</head>
<body>
<label>加密前: </label><input id="data" type="text" placeholder="加密前" style="width: 80%"><br>
<label>加密后: </label><input id="code" type="text" placeholder="加密后" style="width: 80%"><br>
<label>解密后: </label><input id="decode" type="text" placeholder="解密后" style="width: 80%"><br>
<button onclick="test()">test</button>
<script src="https://cdn.staticfile.org/crypto-js/4.0.0/crypto-js.min.js" type="text/javascript"></script>
<script>
    // 偏移量
    let iv = "0000000000000000";
    // 密钥，长度必须为16
    let secret_key = "1234567890123456";
    function parse(string) {
        return CryptoJS.enc.Utf8.parse(string);
    }
    function encrypt(data){
        // Encrypt
        return CryptoJS.AES.encrypt(parse(data), parse(secret_key), {
            iv: parse(iv),
            mode: CryptoJS.mode.CBC,
            padding: CryptoJS.pad.Pkcs7
        }).toString();
    }
    function decrypt(code){
        return CryptoJS.AES.decrypt(code, parse(secret_key),{
            iv: parse(iv),
            mode: CryptoJS.mode.CBC,
            padding: CryptoJS.pad.Pkcs7
        }).toString(CryptoJS.enc.Utf8);
    }
    function test() {
        const data = document.querySelector('#data').value;
        const code = encrypt(data);
        document.querySelector('#code').value = code;
        const decode = decrypt(code);
        document.querySelector('#decode').value = decode;
    }
</script>
</body>
</html>